/**
 * The control menu 
 * @author William
 * 2012-2-26
 */

package com.ytu.clouddisk.face;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GVAdapter extends BaseAdapter {

	Context mContext;
	LayoutInflater mLayoutInflater; // control the layout
	MenuItemData mMenuItemData; // the menu items for choice

	public GVAdapter(Context context, MenuItemData menuItemData) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mMenuItemData = menuItemData;
	}

	public void getData(MenuItemData menuItemData) {
		mMenuItemData = menuItemData;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {

		return mMenuItemData.getCount();
	}

	@Override
	public Object getItem(int pos) {

		return pos;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.menu_item, null);
		}

		ImageView imageView = (ImageView) convertView
				.findViewById(R.id.imageview);
		imageView.setBackgroundDrawable(mMenuItemData.getDrawable(position));

		TextView textView = (TextView) convertView.findViewById(R.id.textview);
		textView.setText(mMenuItemData.getTitle(position));
		return convertView;
	}

}
